package br.com.view;

import br.com.dao.ConectaBanco;
import br.com.dao.ModeloTabela;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;

/**
 *
 * @author Cícero
 */
public class Frm_CadEpi extends javax.swing.JFrame {

    ConectaBanco conexao = new ConectaBanco();
    int codFornecedor;
    String fornecedorEPI;

    public Frm_CadEpi() {
        initComponents();
        conexao.conexao();
        geraTabela("select * from cadastroepi order by idcad_epi");
        buscaForncedor();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblIdCadEPI = new javax.swing.JLabel();
        textIdCadEpi = new javax.swing.JTextField();
        lblCodigoEpi = new javax.swing.JLabel();
        textCodigoEpi = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        textQuantidade = new javax.swing.JTextField();
        lblNomeEpi = new javax.swing.JLabel();
        textNomeEpi = new javax.swing.JTextField();
        lblDescricaoEpi = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        textAreaDescricaoEpi = new javax.swing.JTextArea();
        lblCAEpi = new javax.swing.JLabel();
        textCAEpi = new javax.swing.JTextField();
        lblTipoEpi = new javax.swing.JLabel();
        comboxTipoEpi = new javax.swing.JComboBox();
        lblFornecedorEpi = new javax.swing.JLabel();
        boxFornecedor = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableEPI = new javax.swing.JTable();
        btnPrimeiro = new javax.swing.JButton();
        btnAnterior = new javax.swing.JButton();
        btnProximo = new javax.swing.JButton();
        btnUltimo = new javax.swing.JButton();
        btnN = new javax.swing.JButton();
        btnA = new javax.swing.JButton();
        btnE = new javax.swing.JButton();
        btnC = new javax.swing.JButton();
        btnS = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        lblTamanho = new javax.swing.JLabel();
        lblCor = new javax.swing.JLabel();
        textTamanho = new javax.swing.JTextField();
        textCor = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SysEPI - Cadastro EPI");
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblIdCadEPI.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblIdCadEPI.setText("Codigo");
        getContentPane().add(lblIdCadEPI, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 90, -1, -1));

        textIdCadEpi.setEnabled(false);
        getContentPane().add(textIdCadEpi, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 110, 60, 20));

        lblCodigoEpi.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblCodigoEpi.setText("Codigo Estoque");
        getContentPane().add(lblCodigoEpi, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 90, -1, -1));

        textCodigoEpi.setEnabled(false);
        getContentPane().add(textCodigoEpi, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 110, 170, -1));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("Quantidade");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 90, -1, -1));

        textQuantidade.setEnabled(false);
        getContentPane().add(textQuantidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 110, 50, -1));

        lblNomeEpi.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblNomeEpi.setText("Nome");
        getContentPane().add(lblNomeEpi, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 150, -1, -1));

        textNomeEpi.setEnabled(false);
        getContentPane().add(textNomeEpi, new org.netbeans.lib.awtextra.AbsoluteConstraints(68, 148, 362, -1));

        lblDescricaoEpi.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblDescricaoEpi.setText("Descrição");
        getContentPane().add(lblDescricaoEpi, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 190, -1, -1));

        textAreaDescricaoEpi.setColumns(20);
        textAreaDescricaoEpi.setRows(5);
        textAreaDescricaoEpi.setEnabled(false);
        jScrollPane1.setViewportView(textAreaDescricaoEpi);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 210, 400, 70));

        lblCAEpi.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblCAEpi.setText("CA EPI");
        getContentPane().add(lblCAEpi, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 298, -1, -1));

        textCAEpi.setEnabled(false);
        getContentPane().add(textCAEpi, new org.netbeans.lib.awtextra.AbsoluteConstraints(75, 296, 140, -1));

        lblTipoEpi.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblTipoEpi.setText("Tipo de EPI");
        getContentPane().add(lblTipoEpi, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 298, -1, -1));

        comboxTipoEpi.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Descartável", "Coletivo", "Reutilizável" }));
        comboxTipoEpi.setSelectedIndex(-1);
        comboxTipoEpi.setToolTipText("");
        comboxTipoEpi.setEnabled(false);
        getContentPane().add(comboxTipoEpi, new org.netbeans.lib.awtextra.AbsoluteConstraints(309, 296, 120, -1));

        lblFornecedorEpi.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblFornecedorEpi.setText("Fornecedor");
        getContentPane().add(lblFornecedorEpi, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 370, -1, -1));

        boxFornecedor.setEnabled(false);
        getContentPane().add(boxFornecedor, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 370, 330, -1));

        tableEPI.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane2.setViewportView(tableEPI);

        getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 90, 420, 300));

        btnPrimeiro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (43).png"))); // NOI18N
        btnPrimeiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrimeiroActionPerformed(evt);
            }
        });
        getContentPane().add(btnPrimeiro, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 440, -1, -1));

        btnAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (2).png"))); // NOI18N
        btnAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAnteriorActionPerformed(evt);
            }
        });
        getContentPane().add(btnAnterior, new org.netbeans.lib.awtextra.AbsoluteConstraints(600, 440, -1, -1));

        btnProximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (24).png"))); // NOI18N
        btnProximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProximoActionPerformed(evt);
            }
        });
        getContentPane().add(btnProximo, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 440, -1, -1));

        btnUltimo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (16).png"))); // NOI18N
        btnUltimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUltimoActionPerformed(evt);
            }
        });
        getContentPane().add(btnUltimo, new org.netbeans.lib.awtextra.AbsoluteConstraints(730, 440, -1, -1));

        btnN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon(42).png"))); // NOI18N
        btnN.setText("Novo");
        btnN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNActionPerformed(evt);
            }
        });
        getContentPane().add(btnN, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 440, -1, -1));

        btnA.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (6).png"))); // NOI18N
        btnA.setText("Alterar");
        btnA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAActionPerformed(evt);
            }
        });
        getContentPane().add(btnA, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 440, -1, -1));

        btnE.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (3).png"))); // NOI18N
        btnE.setText("Excluir");
        btnE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEActionPerformed(evt);
            }
        });
        getContentPane().add(btnE, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 440, -1, -1));

        btnC.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (4).png"))); // NOI18N
        btnC.setText("Cancelar");
        btnC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCActionPerformed(evt);
            }
        });
        getContentPane().add(btnC, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 440, -1, -1));

        btnS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones sysepi/favicon (29).png"))); // NOI18N
        btnS.setText("Salvar");
        btnS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSActionPerformed(evt);
            }
        });
        getContentPane().add(btnS, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 440, -1, -1));

        jSeparator1.setForeground(new java.awt.Color(0, 102, 102));
        getContentPane().add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 420, 870, 10));

        jSeparator2.setForeground(new java.awt.Color(0, 102, 102));
        getContentPane().add(jSeparator2, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 58, 860, -1));

        jSeparator3.setForeground(new java.awt.Color(0, 102, 102));
        getContentPane().add(jSeparator3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 402, 880, 0));

        jLabel2.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
        jLabel2.setText("Cadastro EPI");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 20, 130, -1));

        lblTamanho.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblTamanho.setText("Tamanho:");
        getContentPane().add(lblTamanho, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 330, -1, -1));

        lblCor.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblCor.setText("Cor:");
        getContentPane().add(lblCor, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 330, -1, -1));

        textTamanho.setEnabled(false);
        getContentPane().add(textTamanho, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 330, 110, -1));

        textCor.setEnabled(false);
        getContentPane().add(textCor, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 330, 120, -1));

        setSize(new java.awt.Dimension(911, 533));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void btnNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNActionPerformed
        Novo();
    }//GEN-LAST:event_btnNActionPerformed

    private void btnAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAActionPerformed
        conexao.conexao();
        String sqlAlterar = (" update cadastroepi set (nome_epi, descricao_epi, tipo_epi, codprod_epi, ca_epi, quantidade_epi, idfabricante, tamanho_epi, cor_epi) values (?,?,?,?,?,?,?,?,?) where idcad_epi=? ");
        try {
            PreparedStatement pst = conexao.con.prepareStatement(sqlAlterar);
            pst.setString(1, textNomeEpi.getText());
            pst.setString(2, textAreaDescricaoEpi.getText());
            pst.setString(3, (String) comboxTipoEpi.getSelectedItem());
            pst.setString(4, textCodigoEpi.getText());
            pst.setString(5, textCAEpi.getText());
            pst.setInt(6, Integer.parseInt(textQuantidade.getText()));
            pst.setString(7, (String) boxFornecedor.getSelectedItem());
            pst.setInt(8, Integer.parseInt(textIdCadEpi.getText()));
            pst.setString(9,textTamanho.getText());
            pst.setString(10,textCor.getText());
            pst.executeUpdate();
            pst.close();
            JOptionPane.showMessageDialog(null, "Funcionario inserido com Sucesso!");
            geraTabela("select * from cadastroepi order by idcad_epi");
            conexao.desconecta();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Falha ao inserir o Funcionario!/n" + ex);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnAActionPerformed

    private void btnEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEActionPerformed
        conexao.conexao();
        String sqlExcluir = (" delete from cadastroepi where idcad_epi = '" + this.textCodigoEpi.getText() + "'");
        try {
            conexao.executaSQL(sqlExcluir);
            conexao.pst.close();
            JOptionPane.showMessageDialog(null, "Excluido com Sucesso!");
            geraTabela("select * from cadastroepi order by idcad_epi");
            conexao.desconecta();
        } catch (Exception erro) {
            JOptionPane.showMessageDialog(null, "Erro ao excluir/n" + erro);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnEActionPerformed

    private void btnCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCActionPerformed
        Cancelar();
        conexao.desconecta();
    }//GEN-LAST:event_btnCActionPerformed

    private void btnSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSActionPerformed
        fornecedorEPI = (String) boxFornecedor.getSelectedItem();
        buscaCodFornecedor();
        conexao.conexao();
        String sqlInserir = ("INSERT INTO cadastroepi (nome_epi, descricao_epi, tipo_epi, codprod_epi, ca_epi, quantidade_epi, idfabricante,tamanho_epi, cor_epi) values (?,?,?,?,?,?,?,?,?)");
        try {
            PreparedStatement pst = conexao.con.prepareStatement(sqlInserir);
            pst.setString(1, textNomeEpi.getText());
            pst.setString(2, textAreaDescricaoEpi.getText());
            pst.setString(3, (String) comboxTipoEpi.getSelectedItem());
            pst.setString(4, textCodigoEpi.getText());
            pst.setString(5, textCAEpi.getText());
            pst.setInt(6, Integer.parseInt(textQuantidade.getText().trim()));
            pst.setInt(7, codFornecedor);
            pst.setString(8,textTamanho.getText());
            pst.setString(9,textCor.getText());
            pst.execute();
            pst.close();
            JOptionPane.showMessageDialog(null, "Funcionario inserido com Sucesso!");
            Cancelar();
            geraTabela("select * from cadastroepi order by idcad_epi");
            conexao.desconecta();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Falha ao inserir o Funcionario!/n" + ex);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnSActionPerformed

    private void btnPrimeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrimeiroActionPerformed
        Novo();
        conexao.conexao();
        try {
            conexao.executaSQL("select * from cadastroepi");
            conexao.rs.first();
            textIdCadEpi.setText(String.valueOf(conexao.rs.getInt("idcad_epi")));
            textNomeEpi.setText(conexao.rs.getString("nome_epi"));
            textAreaDescricaoEpi.setText(conexao.rs.getString("descricao_epi"));
            textCodigoEpi.setText(String.valueOf(conexao.rs.getInt("codprod_epi")));
            textCAEpi.setText(conexao.rs.getString("ca_epi"));
            textQuantidade.setText(String.valueOf(conexao.rs.getInt("quantidade_epi")));
            textCor.setText(conexao.rs.getString("cor_epi"));
            textTamanho.setText(conexao.rs.getString("tamanho_epi"));
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Erro botao Primeiro/n" + ex);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnPrimeiroActionPerformed

    private void btnUltimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUltimoActionPerformed
        conexao.conexao();
        try {
            conexao.rs.last();
            textIdCadEpi.setText(String.valueOf(conexao.rs.getInt("idcad_epi")));
            textNomeEpi.setText(conexao.rs.getString("nome_epi"));
            textAreaDescricaoEpi.setText(conexao.rs.getString("descricao_epi"));
            textCodigoEpi.setText(String.valueOf(conexao.rs.getInt("codprod_epi")));
            textCAEpi.setText(conexao.rs.getString("ca_epi"));
            textQuantidade.setText(String.valueOf(conexao.rs.getInt("quantidade_epi")));
            textCor.setText(conexao.rs.getString("cor_epi"));
            textTamanho.setText(conexao.rs.getString("tamanho_epi"));
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Erro Último/n" + ex);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnUltimoActionPerformed

    private void btnProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProximoActionPerformed
        conexao.conexao();
        try {
            conexao.rs.next();
            textIdCadEpi.setText(String.valueOf(conexao.rs.getInt("idcad_epi")));
            textNomeEpi.setText(conexao.rs.getString("nome_epi"));
            textAreaDescricaoEpi.setText(conexao.rs.getString("descricao_epi"));
            textCodigoEpi.setText(String.valueOf(conexao.rs.getInt("codprod_epi")));
            textCAEpi.setText(conexao.rs.getString("ca_epi"));
            textQuantidade.setText(String.valueOf(conexao.rs.getInt("quantidade_epi")));
            textCor.setText(conexao.rs.getString("cor_epi"));
            textTamanho.setText(conexao.rs.getString("tamanho_epi"));
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Erro Proximo/n" + ex);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnProximoActionPerformed

    private void btnAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAnteriorActionPerformed
        conexao.conexao();
        try {
            conexao.rs.previous();
            textIdCadEpi.setText(String.valueOf(conexao.rs.getInt("idcad_epi")));
            textNomeEpi.setText(conexao.rs.getString("nome_epi"));
            textAreaDescricaoEpi.setText(conexao.rs.getString("descricao_epi"));
            textCodigoEpi.setText(String.valueOf(conexao.rs.getInt("codprod_epi")));
            textCAEpi.setText(conexao.rs.getString("ca_epi"));
            textQuantidade.setText(String.valueOf(conexao.rs.getInt("quantidade_epi")));
            textCor.setText(conexao.rs.getString("cor_epi"));
            textTamanho.setText(conexao.rs.getString("tamanho_epi"));
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Erro Anterior/n" + ex);
            conexao.desconecta();
        }
        conexao.desconecta();
    }//GEN-LAST:event_btnAnteriorActionPerformed

    private void buscaForncedor() {
        try {
            conexao.conexao();
            conexao.pst = conexao.con.createStatement();
            conexao.rs = conexao.pst.executeQuery("SELECT * FROM cadastrofabricante order by nome_fabricante");
            boxFornecedor.addItem("Selecione o Fornecedor");
            while (conexao.rs.next()) {
                boxFornecedor.addItem(conexao.rs.getObject(4));
            }
            conexao.rs.close();
            conexao.desconecta();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Erro ao preencher box \n" + ex);
            conexao.desconecta();
        }
        conexao.desconecta();
    }

    public void buscaCodFornecedor() {
        conexao.conexao();
        try {
            conexao.executaSQL("select * from cadastrofabricante where nome_fabricante ='" + this.fornecedorEPI + "'");
            conexao.rs.first();
            codFornecedor = conexao.rs.getInt("idfabricante");
        } catch (SQLException erro) {
            JOptionPane.showMessageDialog(null, "Erro ao preencher ComboBoxSetor \n" + erro);
            conexao.desconecta();
        }
        conexao.desconecta();
    }

    private void Novo() {
        textAreaDescricaoEpi.setEnabled(true);
        textCodigoEpi.setEnabled(true);
        textNomeEpi.setEnabled(true);
        textQuantidade.setEnabled(true);
        boxFornecedor.setEnabled(true);
        comboxTipoEpi.setEnabled(true);
        textCor.setEnabled(true);
        textTamanho.setEnabled(true);
        textCAEpi.setEnabled(true);
        textCodigoEpi.requestFocus();
    }

    private void Cancelar() {
        textAreaDescricaoEpi.setEnabled(false);
        textCodigoEpi.setEnabled(false);
        textNomeEpi.setEnabled(false);
        textQuantidade.setEnabled(false);
        boxFornecedor.setEnabled(false);
        comboxTipoEpi.setEnabled(false);
        textCAEpi.setEnabled(false);
        textCor.setEnabled(false);
        textTamanho.setEnabled(false);
        textAreaDescricaoEpi.setText("");
        textCodigoEpi.setText("");
        textNomeEpi.setText("");
        textQuantidade.setText("");
        textCor.setText("");
        textTamanho.setText("");
        textCAEpi.setText("");
        boxFornecedor.setSelectedIndex(0);
        comboxTipoEpi.setSelectedIndex(0);
        
    }

    public void geraTabela(String SQL) {
        ArrayList dados = new ArrayList();
        String[] Colunas = new String[]{"Codigo Produto", "Nome", "CA", "Quantidade"};
        conexao.executaSQL(SQL);
        try {
            conexao.rs.first();
            do {
                dados.add((new Object[]{conexao.rs.getString("codprod_epi"), conexao.rs.getString("nome_epi"), conexao.rs.getString("ca_epi"), conexao.rs.getInt("quantidade_epi")}));
            } while (conexao.rs.next());
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Erro ao preencher o arrayList cadEpi/n" + ex);
            conexao.desconecta();
        }
        ModeloTabela modeloTabela = new ModeloTabela(dados, Colunas);
        tableEPI.setModel(modeloTabela);
        tableEPI.getColumnModel().getColumn(0).setPreferredWidth(100);
        tableEPI.getColumnModel().getColumn(0).setResizable(false);
        tableEPI.getColumnModel().getColumn(1).setPreferredWidth(280);
        tableEPI.getColumnModel().getColumn(1).setResizable(false);
        tableEPI.getColumnModel().getColumn(2).setPreferredWidth(60);
        tableEPI.getColumnModel().getColumn(2).setResizable(false);
        tableEPI.getColumnModel().getColumn(3).setPreferredWidth(60);
        tableEPI.getColumnModel().getColumn(3).setResizable(false);

        tableEPI.getTableHeader().setReorderingAllowed(false);
        tableEPI.setAutoResizeMode(tableEPI.AUTO_RESIZE_OFF);
        tableEPI.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Frm_CadSetor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Frm_CadSetor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Frm_CadSetor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Frm_CadSetor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Frm_CadEpi().setVisible(true);
            }
        });
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox boxFornecedor;
    private javax.swing.JButton btnA;
    private javax.swing.JButton btnAnterior;
    private javax.swing.JButton btnC;
    private javax.swing.JButton btnE;
    private javax.swing.JButton btnN;
    private javax.swing.JButton btnPrimeiro;
    private javax.swing.JButton btnProximo;
    private javax.swing.JButton btnS;
    private javax.swing.JButton btnUltimo;
    private javax.swing.JComboBox comboxTipoEpi;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JLabel lblCAEpi;
    private javax.swing.JLabel lblCodigoEpi;
    private javax.swing.JLabel lblCor;
    private javax.swing.JLabel lblDescricaoEpi;
    private javax.swing.JLabel lblFornecedorEpi;
    private javax.swing.JLabel lblIdCadEPI;
    private javax.swing.JLabel lblNomeEpi;
    private javax.swing.JLabel lblTamanho;
    private javax.swing.JLabel lblTipoEpi;
    private javax.swing.JTable tableEPI;
    private javax.swing.JTextArea textAreaDescricaoEpi;
    private javax.swing.JTextField textCAEpi;
    private javax.swing.JTextField textCodigoEpi;
    private javax.swing.JTextField textCor;
    private javax.swing.JTextField textIdCadEpi;
    private javax.swing.JTextField textNomeEpi;
    private javax.swing.JTextField textQuantidade;
    private javax.swing.JTextField textTamanho;
    // End of variables declaration//GEN-END:variables
}
